<body onload="init()">
<script type="text/javascript" src="js/jquery-1.5.2.min.js"></script>
<script>
function addUrl()
{
	var url = $("#addUrl").val();
//	var time = Number ($("#addTime").val());
//	alert(url + " " + time);
	/*
	if ( time == Number.NaN )
	{
		alert("时间不是数字!");
		return;
	}
	*/
	if ( validateUrl(url) == false )
	{
		alert("请填写符合格式的URL，例如renren.com");
		return;
	}
//	if ( url.indexOf("http://") != 0 )
//		url = "http://" + url;
	var urlList = localStorage['urlList'];
	if ( urlList != null )
		localStorage['urlList'] = urlList + "," + url;
	else
		localStorage['urlList'] = url;
//	localStorage[url] = time;

	updateList();
}

function init()
{
	$("#addButton").click(addUrl);
	updateList();
}

function updateList ()
{
	var urlTable = $("#urlTable");
	urlTable.empty();
	urlTable.append("<tr><th>URL</th><th>Option</th></tr>");
	var urls = localStorage['urlList'].split(",");
	for (var i = 0; i < urls.length; i ++)
	{
		if ( urls[i] == "" )
			continue;
		var rowId = "row" + i;
		urlTable.append("<tr><td id=" + rowId + ">" + urls[i] + 
				"</td><td><button onclick='delList(" + rowId + ")'>delete</button></td></tr>");
	}
}

function delList (rowId)
{
//	alert("delete " + rowId.innerHTML);
	var delUrl = rowId.innerHTML;
	var tmpUrls = "";
	var urls = localStorage['urlList'].split(",");
	for (var i = 0; i < urls.length; i ++)
	{
		if ( urls[i] != delUrl )
			tmpUrls += "," + urls[i];
	}
	localStorage['urlList'] = tmpUrls;
//	localStorage.removeItem(delUrl);

	updateList();
}

function validateUrl (url)
{
	return ( url.match(/\w+\.\w+/) != null )
}

</script>
	<html>
		目前监控的网站：
		<table id="urlTable">
		</table>

		<br/><br/>
		<form>
		URL:(例如renren.com)<br/>
		<input type="text" id="addUrl"/>
		<input type="submit" id="addButton" value="Add">
		</form>
	</html>
</body>
